/**
 * @author LKQ
 * @date 2022/2/24 15:51
 * @description 数学
 */
public class FormalSolution2 {
    public static void main(String[] args) {
        FormalSolution2 formalSolution2 = new FormalSolution2();
        formalSolution2.xorOperation(5, 0);
    }
    public int xorOperation(int n, int start) {
        int s = start >> 1, e = n & start & 1;
        int ret = sumXor(s - 1) ^ sumXor(s + n - 1);
        return ret << 1 | e;
    }

    public int sumXor(int x) {
        if (x % 4 == 0) {
            return x;
        }
        if (x % 4 == 1) {
            return 1;
        }
        if (x % 4 == 2) {
            return x + 1;
        }
        return 0;
    }
}
